package com.ruoyi.project.module.dictionary.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.module.dictionary.domain.Dictionarys;
import com.ruoyi.project.module.dictionary.service.IDictionaryService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.framework.web.domain.AjaxResult;

/**
 * 宠物字典 信息操作处理
 * 
 * @author ruoyi
 * @date 2018-11-16
 */
@Controller
@RequestMapping("/module/dictionary")
public class DictionaryController extends BaseController
{
    private String prefix = "module/dictionary";
	
	@Autowired
	private IDictionaryService dictionaryService;
	
	@RequiresPermissions("module:dictionary:view")
	@GetMapping()
	public String dictionary()
	{
	    return prefix + "/dictionary";
	}
	
	/**
	 * 查询宠物字典列表
	 */
	@RequiresPermissions("module:dictionary:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Dictionarys dictionary)
	{
		startPage();
        List<Dictionarys> list = dictionaryService.selectDictionaryList(dictionary);
		return getDataTable(list);
	}
	
	/**
	 * 新增宠物字典
	 */
	@GetMapping("/add")
	public String add()
	{

		return prefix + "/add";
	}
	
	/**
	 * 新增保存宠物字典
	 */
	@RequiresPermissions("module:dictionary:add")
	@Log(title = "宠物字典", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Dictionarys dictionary)
	{		

		return toAjax(dictionaryService.insertDictionary(dictionary));
	}

	/**
	 * 修改宠物字典
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Integer id, ModelMap mmap)
	{
		Dictionarys dictionary = dictionaryService.selectDictionaryById(id);
		mmap.put("dictionary", dictionary);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存宠物字典
	 */
	@RequiresPermissions("module:dictionary:edit")
	@Log(title = "宠物字典", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Dictionarys dictionary)
	{		
		return toAjax(dictionaryService.updateDictionary(dictionary));
	}
	
	/**
	 * 删除宠物字典
	 */
	@RequiresPermissions("module:dictionary:remove")
	@Log(title = "宠物字典", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(dictionaryService.deleteDictionaryByIds(ids));
	}
	
}
